package P1500;

import java.util.Scanner;

/**
 * @author: zhouyang
 * @descrpition:
 * @time: 2019-10-18 14:27
 */
public class P1563_玩具谜题 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();//有几个小人
        int m = scanner.nextInt();//有多少指令
        int[] direction = new int[n];//0圈内 1圈外
        String[] names = new String[n];
        for(int i=0;i<n;++i){
            direction[i] = scanner.nextInt();
            names[i] = scanner.next();
        }
        int index=0;
        while(m-- > 0){
            int d = scanner.nextInt();//0左数
            int dis = scanner.nextInt();
            if(d == direction[index]){//反着数
                index = (index-dis+n)%n;
            }else{
                index = (index+dis)%n;
            }
        }
        System.out.println(names[index]);
    }
}
